#include "mainwindow.h"
#include <QLabel>
#include <QListWidget>
#include <QHBoxLayout>
#include <QTreeWidget>
#include <QTableWidget>

MainWindow::MainWindow(QWidget* parent)
    : QMainWindow(parent)
{
    // - QListWidget
    QLabel* lbl = new QLabel(this);
    lbl->setFixedWidth(70);
    QListWidget* listWidget = new QListWidget(this);

    new QListWidgetItem(QIcon(":/1.jpg"), tr("1.jpg"), listWidget);
    new QListWidgetItem(QIcon(":/2.png"), tr("2.png"), listWidget);

    listWidget->addItem(new QListWidgetItem(QIcon(":/3.ico"), tr("3.ico")));

    QListWidgetItem* newItem = new QListWidgetItem;
    newItem->setIcon(QIcon(":/4.ico"));
    newItem->setText(tr("4.ico"));
    listWidget->addItem(newItem);

    QHBoxLayout* layout = new QHBoxLayout;
    layout->addWidget(lbl);
    layout->addWidget(listWidget);
    QWidget* w = new QWidget(this);
    w->setLayout(layout);
    this->setCentralWidget(w);

    connect(listWidget, &QListWidget::currentTextChanged, lbl, &QLabel::setText);

    //    listWidget->setViewMode(QListView::IconMode); // icon mode

    // - QTreeWidget
    QTreeWidget* tree = new QTreeWidget;
    //    tree->setColumnCount(2);
    //    QStringList headers;
    //    headers << tr("left") << tr("right");
    //    tree->setHeaderLabels(headers);
    tree->setHeaderLabels(QStringList() << tr("left") << tr("right"));
    //    tree->setHeaderHidden(this);

    QTreeWidgetItem* root = new QTreeWidgetItem(tree, QStringList() << tr("Root") << tr("000"));
    new QTreeWidgetItem(root, QStringList() << tr("Leaf 1") << tr("001"));
    QTreeWidgetItem* leaf2 = new QTreeWidgetItem(root, QStringList() << tr("Leaf 2") << tr("002"));
    leaf2->setCheckState(0, Qt::Checked);

    //    QList<QTreeWidgetItem*> rootList;
    //    rootList << root;
    //    tree->insertTopLevelItems(root);
    tree->addTopLevelItem(root);

    layout->addWidget(tree);

    // - QTableWidget
    QTableWidget* tbl = new QTableWidget;
    tbl->setColumnCount(4);
    tbl->setRowCount(5);

    QStringList headers;
    headers << "ID"
            << "Name"
            << "Age"
            << "Sex";
    tbl->setHorizontalHeaderLabels(headers);

    tbl->setItem(0, 0, new QTableWidgetItem(QString("0001")));
    tbl->setItem(1, 0, new QTableWidgetItem(QString("0002")));
    tbl->setItem(2, 0, new QTableWidgetItem(QString("0003")));
    tbl->setItem(3, 0, new QTableWidgetItem(QString("0004")));
    tbl->setItem(4, 0, new QTableWidgetItem(QString("0005")));
    tbl->setItem(0, 1, new QTableWidgetItem(QString("20100112")));

    layout->addWidget(tbl);
}

MainWindow::~MainWindow()
{
}
